package com.sunedai.tiger.web.config;

import com.sunedai.tiger.web.interceptor.CommonInterceptor;
import com.sunedai.tiger.web.interceptor.EmpLoginInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.PathMatchConfigurer;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 配置拦截器
 * @author zhaolipeng
 */
@Configuration
public class WebConfig implements WebMvcConfigurer {

  /**
   * 烂机器配置
   * @param registry -- 拦截器注册器
   */
  @Override
  public void addInterceptors(InterceptorRegistry registry) {
    registry.addInterceptor(new CommonInterceptor())
        .excludePathPatterns("/static/**");
    registry.addInterceptor(new EmpLoginInterceptor())
        .addPathPatterns("/emp/**")
        .excludePathPatterns("/emp/login",
            "/error");
  }

  @Override
  public void addViewControllers(ViewControllerRegistry registry) {
    registry.addRedirectViewController("/", "/emp/login");
  }

  @Override
  public void configurePathMatch(PathMatchConfigurer configurer) {
    configurer.setUseSuffixPatternMatch(false);
  }
}
